package cn.fl.mcr.service.impl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;

import cn.cmm.base.framework.utils.DateUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.mcr.service.IMcrInformTransferService;
import cn.fl.mcr.vo.McrBuyBackFailVO;
import cn.lionbridgecapital.loan.model.condition.McrInformTransferQC;
import cn.lionbridgecapital.loan.model.dto.McrInformTransferDTO;
import cn.lionbridgecapital.loan.model.exception.BaseException;
import cn.lionbridgecapital.loan.model.utils.CollectionUtils;
import cn.lionbridgecapital.loan.service.api.IMcrInformTransferApiService;
import cn.lionbridgecapital.loan.utils.BaseLogUtils;

@Service
public class IMcrInformTransferServiceImpl implements IMcrInformTransferService {

	private static final Logger logger = LoggerFactory.getLogger(IMcrInformTransferServiceImpl.class);
	@Autowired
	private IMcrInformTransferApiService mcrInformTransferApiService;
	
	@Override
	public List<McrBuyBackFailVO> selectBuyBackList(String batchNo,Long billId) throws BaseException {
		List<McrBuyBackFailVO> voList = Lists.newArrayList();
		List<Map<String, Object>> selectBuyBackList = mcrInformTransferApiService.selectBuyBackList(batchNo,billId);
		BaseLogUtils.info(logger, "selectBuyBackList", "IMcrInformTransferApiService.selectBuyBackList>>selectBuyBackList:"+JSON.toJSONString(selectBuyBackList),CurrentThreadContext.getCurrentUserName());
		if(CollectionUtils.isNotEmpty(selectBuyBackList)) {
			 for(Map<String, Object> map:selectBuyBackList) {
				 McrBuyBackFailVO buyBackFialVo = new McrBuyBackFailVO();
				 buyBackFialVo.setBillId(Long.valueOf(String.valueOf(map.get("BILLID"))));
				 buyBackFialVo.setSqBuyBackBatchNo(String.valueOf(map.get("SQBUYBACKBATCHNO")));
				 buyBackFialVo.setCrCntNo(String.valueOf(map.get("CRCNTNO")));
				 buyBackFialVo.setCstNm(String.valueOf(map.get("CSTNM")));
				 buyBackFialVo.setCrDt(DateUtils.formatStringToDate(String.valueOf(map.get("CRDT")), DateUtils.YYYY_MM_DDHHMMSS) );
				 buyBackFialVo.setCrtTm(DateUtils.formatStringToDate(String.valueOf(map.get("CRTTM")), DateUtils.YYYY_MM_DDHHMMSS) );
				 buyBackFialVo.setRepSts(String.valueOf(map.get("REPSTS")));
				 if(null != map.get("USERNAME")) {
					 buyBackFialVo.setUserName(String.valueOf(map.get("USERNAME")));
				 }
				 if(null !=map.get("MDFTM")) {
					 buyBackFialVo.setMdfTm(DateUtils.formatStringToDate(String.valueOf(map.get("MDFTM")), DateUtils.YYYY_MM_DDHHMMSS));
				 }
				 buyBackFialVo.setCapAmt(Long.valueOf(String.valueOf(map.get("CAPAMT"))));
				 buyBackFialVo.setIntrAmt(Long.valueOf(String.valueOf(map.get("INTRAMT"))));
				 buyBackFialVo.setPenaltyAmt( Long.valueOf(String.valueOf(map.get("PENALTYAMT"))));
				 buyBackFialVo.setTotalAmt( Long.valueOf(String.valueOf(map.get("TOTALAMT"))));
				 buyBackFialVo.setYhCapAmt( Long.valueOf(String.valueOf(map.get("YHCAPAMT"))));
				 buyBackFialVo.setYhIntrAmt( Long.valueOf(String.valueOf(map.get("YHINTRAMT"))));
				 buyBackFialVo.setYhPenaltyAmt( Long.valueOf(String.valueOf(map.get("YHPENALTYAMT"))));
				 buyBackFialVo.setYhTotalAmt( Long.valueOf(String.valueOf(map.get("YHTOTALAMT"))));
				 voList.add(buyBackFialVo);
			 }
		}
		 
		return voList;
	}

	@Override
	public List<McrInformTransferDTO> searchMcrInformTransferDTOList(McrInformTransferQC qc) throws BaseException {
		// TODO Auto-generated method stub
		return mcrInformTransferApiService.searchMcrInformTransferDTOList(qc);
	}

	@Override
	public boolean modifyMcrInformTransferDTO(McrInformTransferDTO entity) throws BaseException {
		// TODO Auto-generated method stub
		return mcrInformTransferApiService.modifyMcrInformTransferDTO(entity);
	}

}
